<?php
/**
 * This file is part of Task Agile.
 * Task Agile is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License.
 * Task Agile is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Task Agile.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @category   TaskAgile
 * @package    Controller
 * @copyright  Copyright (c) 20010-2010 Estrada Virtual (http://estradavirtual.com.br)
 * @license    http://www.gnu.org/licenses/gpl.txt GPLv3
 * @version    $Id$
*/
?>
<script type="text/javascript" src="js/swfobject.js"></script>
<script type="text/javascript" src="js/jquery/jquery.uploadify.v2.1.0.min.js"></script>

<form action="task/task/forward" method="post" class="yform" role="application">
    <fieldset>
        <legend>Tarefa</legend>
        Projeto : <b><?php echo $this->project->name; ?></b><br />
        Tarefa : <b><?php echo $this->task->name; ?></b><br />
        Prioridade : <b><?php echo $this->prioritys[$this->task->priority]; ?></b><br />
        Criador da tarefa : <b><?php echo $this->users[$this->task->fk_user_create]; ?></b><br />
        Descrição: <b><?php echo nl2br($this->task->description); ?></b><br />
        <?php if (Zend_Auth::getInstance()->getIdentity()->id === $this->task->fk_user &&
                  $this->task->status == Task::STATUS_ACTIVE) : ?>
        <div class="type-button">
            <input type="button" class="reset" id="closeTask" value="Finalizar tarefa"> <br />
            <input type="button" class="reset" id="inactiveTask" value="Congela tarefa"> <br />
            <input type="hidden" name="idTask" value="<?php echo $this->task->id; ?>">
            <input type="submit" value="Encaminhar"> para :<?php echo $this->formSelect('to', null, array('id' => 'to', 'title' => $this->translate('fk_user')), $this->usersProject); ?>
        </div>
        <?php endif; ?>
    </fieldset>
    <fieldset>
        <legend>Arquivos</legend>
            <div id="upload_container"></div>
            <div id="allfiles"><?php echo $this->action('list-by-task', 'file', 'default', array('id' => $this->task->id)); ?></div>
    </fieldset>
</form>
<form action="task/task/comment" method="post" class="yform" id="formComment" role="application">
    <input type="hidden" name="idTask" value="<?php echo $this->task->id; ?>">
    Atividade/Anotação: <br />
    <textarea name="comment" rows="7" cols="80" class="required"></textarea>
    <br />
    Duração:
    <input type="text" name="hours" size="6" maxlength="5" id="hours" value="00:00"/>(HH:MM)<br/>
    <input type="submit" value="Gravar Anotação" />
</form>

<h3>Atividades/Anotações:</h3>
<table border="1px" width="100%">
    <tr>
        <th>Data</th>
        <th>Duração</th>
        <th>Usuário</th>
        <th>Anotação</th>
    </tr>
<?php
$comments = $this->comments;
foreach ($comments as $comment) :
    $hours = $comment->hours ? $comment->hours : '00:00';
?>
    <tr>
        <td><?php echo  $this->dateFormat($comment->dt_register, 'd/m/Y \à\s H:i:s'); ?></td>
        <td><?php echo  $this->dateFormat($hours, 'H:i'); ?></td>
        <td><?php echo $this->users[$comment->fk_user]; ?></td>
        <td width="60%"><?php echo nl2br(htmlspecialchars($comment->comment)); ?></td>
    </tr>
<?php endforeach ?>
</table>

<script type="text/javascript">
$().ready(function(){
    $('#closeTask').click(function() {
        if (confirm('Deseja finalizar esta tarefa?')) {
            self.location = "<?php echo $this->serverUrl() . $this->baseUrl(); ?>/task/task/close/id/<?php echo $this->task->id; ?>";
        }
    });
    $('#inactiveTask').click(function() {
        if (confirm('Deseja congelar esta tarefa?')) {
            self.location = "<?php echo $this->serverUrl() . $this->baseUrl(); ?>/task/task/inactivate/id/<?php echo $this->task->id; ?>";
        }
    });
    $('#formComment').validate({ignoreTitle:true});
    $('#hours').setMask('99:99');


    // upload
    $('#upload_container').uploadify({
        'uploader' : '<?php echo $this->baseUrl('/swf/uploadify.swf'); ?>',
        'script'   : '<?php echo $this->url(array('module' => 'default', 'controller' => 'file', 'action' => 'upload', 'id' => $this->task->id, 'idUser' => Zend_Auth::getInstance()->getIdentity()->id)); ?>',
        'checkScript': '<?php echo $this->url(array('module' => 'default', 'controller' => 'file', 'action' => 'check-by-task', 'id' => $this->task->id)); ?>',
        'folder'   : '<?php echo $this->baseUrl('/uploads'); ?>',
        'cancelImg': '<?php echo $this->baseUrl('/img/upload_cancel.png'); ?>',
        'auto'     : true,
        'multi' : true,
        'onComplete'  : function(event, queueID, fileObj, response, data) {$('#allfiles').load(location.href+" #allfiles>*",""); },
        'onError'  : function(event, queueID, fileObj, errorObj) {alert(errorObj.info);},
        'height' : '32',
        'width' : '250'
        //'buttonImg' : 'img/browse.png'
    });
});

</script>
